package cn.vihub.controller;
import cn.vihub.param.ShopBrandParam;
import cn.vihub.pojo.ShopBrandInfo;
import cn.vihub.service.ShopBrandInfoService;
import cn.vihub.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

/**
* (shop_brand_info)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/shop-store/brandInfo")
public class ShopBrandInfoController {
/**
* 服务对象
*/
    @Autowired
    private ShopBrandInfoService shopBrandInfoService;


    /**
     * @author: 秋晚
     * @description:分页模糊查询
     * @params: [cn.vihub.param.ShopBrandParam]
     * @return: cn.vihub.utils.Result<com.baomidou.mybatisplus.core.metadata.IPage<cn.vihub.pojo.ShopBrandInfo>>
     * @date: 2025/7/25 8:52
     */
    @GetMapping("pageShopBrand")
    public Result<IPage<ShopBrandInfo>> pageShopBrand(@RequestHeader("X-User-Id") String userId, ShopBrandParam shopBrandParam){
        return Result.success(shopBrandInfoService.pageShopBrand(shopBrandParam));
    }


    /**
     * @author: 秋晚
     * @description:保存或编辑品牌
     * @params: [cn.vihub.param.ShopBrandParam]
     * @return: cn.vihub.utils.Result<java.lang.Boolean>
     * @date: 2025/7/25 8:52
     */
    @PostMapping("saveBrand")
    public Result<Boolean> saveBrand(@RequestBody ShopBrandParam shopBrandParam){
        //创建一个实体对象
        ShopBrandInfo shopBrandInfo = new ShopBrandInfo();
        //拷贝赋值
        BeanUtils.copyProperties(shopBrandParam,shopBrandInfo);
        //进行添加
        return Result.success(shopBrandInfoService.saveOrUpdate(shopBrandInfo));
    }


    /**
     * @author: 秋晚
     * @description:根据id删除品牌
     * @params: [java.lang.Integer]
     * @return: cn.vihub.utils.Result<java.lang.Boolean>
     * @date: 2025/7/25 8:52
     */
    @DeleteMapping("deleteById/{id}")
    public Result<Boolean> deleteById(@PathVariable(name = "id") Integer id){
        return Result.success(shopBrandInfoService.removeById(id));
    }




}
